//课程训练列表页
require('../css/sports-course.less')

document.ready(function () {

    window.utils.checkUserLogin()
    
    const BASE_URL = 'http://139.9.177.51:8099'
    //底部导航
    window.utils.addTab(1)

    let user = JSON.parse(localStorage.getItem('user'));

    // 获取dom节点
    let newCourse = document.querySelector('#newCourse');
    let generalCourse = document.querySelector('#generalCourse');

    // 获取训练课程详情
    $http.get(`/sports/courseList?id=${user.userId}`, function (res) {
        // console.log(res.data);
        // 最新课程
        let latestCourseData = res.data.find(function (item) {
            return item.latest === 1
        })
        //创建节点
        let curriculum = document.createElement('div');
        curriculum.innerHTML = `
                <a class="course-item-link" href="./course-particulars.html?courseId=${latestCourseData.courseId}">
                    <img src="${BASE_URL}${latestCourseData.imgurl}">
                    <div class="conBox">
                        <div class="title fw">${latestCourseData.name}</div>
                        <p class="desc">${latestCourseData.desc}</p>
                    </div>
                </a>
        `
        newCourse.appendChild(curriculum); //显示到页面

        // 普通课程
        let courseListData = res.data.filter(function (item) {
            return item.latest === 0
        })
        
        //拼接普通课程节点
        let html = '';
        courseListData.forEach(function (item) {
            html += `
                    <a class="course-item-link1" href="./course-particulars.html?courseId=${item.courseId}">
                        <img src="${'http://139.9.177.51:8099' + item.imgurl}" alt="">
                        <div class="con-Box">
                            <div class="title fw">${item.name}</div>
                            <p class="desc">${item.desc}</p>
                        </div>                       
                    </a>
            `
        })
        generalCourse.innerHTML=html
    })





})